﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class LibraryDetails : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ManageLibrary manager = new ManageLibrary();
            String ID = Request.QueryString["id"];
            Library lib = manager.getLibrary(ID);

            txtLibraryName.Text = lib.Name;
            txtMotto.Text = lib.Motto;
            txtLibrarian.Text = lib.HeadLibrarian;
            txtPhoneNumber.Text = lib.PhoneNumber;
            txtAddress.Text = lib.Address;
            txtCity.Text = lib.City;

            UtilityManager util = new UtilityManager();
            DataSet ds = util.getStates();
            ddlState.DataSource = ds.Tables[0];
            ddlState.DataTextField = ds.Tables[0].Columns["State"].ColumnName.ToString();
            ddlState.DataValueField = ds.Tables[0].Columns["State"].ColumnName.ToString();
            ddlState.DataBind();
            ddlState.SelectedValue = lib.State;

            txtEmail.Text = lib.Email;
            txtHours.Text = lib.Hours;

            txtFinePerDay.Text = lib.FinePerDay.ToString();
            txtMaxFinetoCheckOut.Text = lib.MaxFineToCheckOut.ToString();
            txtReserveFee.Text = lib.ReserveFee.ToString();

            txtCheckoutLength.Text = lib.CheckoutLength.ToString();
            txtMaxTimesRenewable.Text = lib.MaxTimesRenewable.ToString();
            txtRenewLength.Text = lib.RenewLength.ToString();

            ddlTheme.SelectedValue = lib.Theme;
        }
        
    }
    protected void btnSaveDetails_Click(object sender, EventArgs e)
    {
        Library ulib = new Library();
        ulib.LibraryID = Convert.ToInt32(Request.QueryString["id"]);

        ulib.Name = txtLibraryName.Text;
        ulib.Motto = txtMotto.Text;
        ulib.HeadLibrarian = txtLibrarian.Text;
        ulib.PhoneNumber = txtPhoneNumber.Text;
        ulib.Address = txtAddress.Text;
        ulib.City = txtCity.Text;
        ulib.State = ddlState.SelectedValue;
        ulib.Email = txtEmail.Text;
        ulib.Hours = txtHours.Text;

        ulib.FinePerDay = Convert.ToSingle(txtFinePerDay.Text);
        ulib.MaxFineToCheckOut = Convert.ToSingle(txtMaxFinetoCheckOut.Text);
        ulib.ReserveFee = Convert.ToSingle(txtReserveFee.Text);

        ulib.CheckoutLength = Convert.ToInt32(txtCheckoutLength.Text);
        ulib.MaxTimesRenewable = Convert.ToInt32(txtMaxTimesRenewable.Text);
        ulib.RenewLength = Convert.ToInt32(txtRenewLength.Text);

        ulib.Theme = ddlTheme.SelectedValue;

        ManageLibrary manager = new ManageLibrary();

        manager.updateLibrary(ulib);
    }
}
